function [Tn, cv] = obj_at_as10(para, profit_lb, profit_ub, ...
    firm_outcome, is_equi_data, N_mkt, ...
    g_ar, rand_seed, tau_reps, sig_level, correlated_fc, corr_sim_at)
% apply AS10 estimator to AT inequalities

if correlated_fc
    prob_lb = normcdf((profit_lb - para(1) - corr_sim_at*para(3))/para(2)); % N_mkt x N x N_corr_sim
    prob_ub = normcdf((profit_ub - para(1) - corr_sim_at*para(3))/para(2));
else
    prob_lb = normcdf((profit_lb - para(1))/para(2)); % N_mkt x N
    prob_ub = normcdf((profit_ub - para(1))/para(2));
end
clear profit_lb profit_ub;

% simulate the choice probabilities for each market
N_firm_outcome = size(firm_outcome, 1);

% check equilibrium
equi_lb = zeros(N_mkt, N_firm_outcome);
equi_ub = zeros(N_mkt, N_firm_outcome);

for i = 1 : N_firm_outcome
    all_outcome_i = firm_outcome(i, :);

    equi_lb(:, i) = mean(prod((prob_lb.^(all_outcome_i==1)).*((1 - prob_ub).^(all_outcome_i==0)), 2), 3);
    equi_ub(:, i) = mean(prod((prob_ub.^(all_outcome_i==1)).*((1 - prob_lb).^(all_outcome_i==0)), 2), 3);
end
clear firm_outcome prob_lb prob_ub;

% the moment conditions
% m<=0
is_equi_data = is_equi_data'; % N_mkt x N_firm_outcome
m = [equi_lb(:, 1:end-1) - is_equi_data(:, 1:end-1), is_equi_data(:, 1:end-1) - equi_ub(:, 1:end-1)];
clear equi_lb equi_ub is_equi_data 

% AS test statistic and critical value
[Tn, cv] = as10_test_corr(m, g_ar, N_mkt, rand_seed, tau_reps, ...
    sig_level, false);













